<%@ page language="java" contentType="text/html; charset=utf-8" %>
<%@ include file="../taglibs.jsp" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>系统设置</title>
<link rel="stylesheet" type="text/css" href="${webroot}/css/style.css" />
<link rel="stylesheet" type="text/css" href="${webroot}/scripts/ext/resources/css/ext-all.css" />
<script type="text/javascript" src="${webroot}/scripts/ext/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="${webroot}/scripts/ext/ext-all.js"></script>
<script type="text/javascript" src="${webroot}/scripts/ext/locale/ext-lang-zh_CN.js"></script>
<script type="text/javascript" src="${webroot}/scripts/jquery.js"></script>
<script type="text/javascript">
<!--

Ext.BLANK_IMAGE_URL = '${webroot}/include/ext/resources/images/default/s.gif';

Ext.namespace('HaiChuan');

Ext.onReady(function(){

    Ext.QuickTips.init();

    HaiChuan.webroot = '${webroot}';

    var store = new Ext.data.JsonStore({
        proxy: new Ext.data.HttpProxy({
            //method: 'GET',
            prettyUrls: false,
            url: HaiChuan.webroot + '/ajax/configurator/listSystemConfig.do',
            api: {
                // all actions except the following will use above url
                update: HaiChuan.webroot + '/ajax/configurator/updateSystemConfig.do'
            }
        }),
        writer: new Ext.data.JsonWriter({
            encode: true,
            listful: true
        }),
        autoSave: false,
        totalProperty: 'totalCount',
        root: 'items',
        id: 'id',
        fields: [
            'id', 'name', 'descript', 'value'
        ]
    });

    var g = Ext.grid,
        f = Ext.form;
    var bfield = new f.Field({
        autoCreate: {tag: 'select', children: [
            {tag: 'option', value: 'true', html: 'true'},
            {tag: 'option', value: 'false', html: 'false'}
        ]},
        getValue : function(){
            return this.el.dom.value == 'true';
        }
    });
    var editors = {
        'date' : new g.GridEditor(new f.DateField({selectOnFocus:true})),
        'string' : new g.GridEditor(new f.TextField({selectOnFocus:true})),
        'number' : new g.GridEditor(new f.NumberField({selectOnFocus:true, style:'text-align:left;'})),
        'boolean' : new g.GridEditor(bfield, {
            autoSize: 'both'
        })
    };
    var cm = new Ext.grid.ColumnModel({
        columns: [
            {
                id: 'name',
                header: '名称',
                dataIndex: 'name',
                width: 130,
                menuDisabled: true
            }, {
                id: 'descript',
                header: '描述',
                dataIndex: 'descript',
                width: 220,
                menuDisabled: true
            }, {
                header: '值',
                dataIndex: 'value',
                width: 100,
                menuDisabled: true
            }
        ],

        // private
        isCellEditable : function(colIndex, rowIndex){
            return colIndex == 2;
        },

        // private
        getRenderer : function(col){
            return col == 2 ? this.renderCell :
                Ext.grid.ColumnModel.prototype.getRenderer.call(this, col);
        },

        // private
        renderCell : function(val){
            var rv = val;
            if(Ext.isDate(val)){
                rv = val.dateFormat('Y-m-j');
            }else if(typeof val == 'boolean'){
                rv = val ? 'true' : 'false';
            }
            return Ext.util.Format.htmlEncode(rv);
        },

       // private
        getCellEditor : function(colIndex, rowIndex){
            var p = store.getAt(rowIndex),
                n = p.data.name,
                val = p.data.value;
            if(Ext.isDate(val)){
                return editors.date;
            }else if(typeof val == 'number'){
                return editors.number;
            }else if(typeof val == 'boolean'){
                return editors['boolean'];
            }else{
                return editors.string;
            }
        }
     });

    // create the editor grid
    var grid = new Ext.grid.EditorGridPanel({
        store: store,
        renderTo: 'systemconfig-div',
        width: 600,
        height: 300,
        autoExpandColumn: 'descript', // column with this id will be expanded
        title: '系统配置',
        frame: true,
        enableColumnMove:false,
        stripeRows:false,
        trackMouseOver: false,
        clicksToEdit:1,
        enableHdMenu : false,
        viewConfig : {
            forceFit:true
        },
        cm: cm,
        buttons: [{
            text: '保存',
            handler: function(){
                store.save();
            }
        },{
            text: '取消',
            handler: function(){
                store.rejectChanges();
            }
        }]
    });

    grid.mon(grid.selModel, 'beforecellselect', function(sm, rowIndex, colIndex){
            if(colIndex === 0 || colIndex === 1){
                grid.startEditing.defer(200, grid, [rowIndex, 2]);
                return false;
            }
        }, this);
    grid.getGridEl().addClass('x-props-grid');

    store.load();

});

//-->
</script>
</head>
<body>
<div id="systemconfig-div" style="margin-top:20px; margin-left:20px;"></div>
</body>
</html>
